package com.company.manage.system.dao;

import com.company.manage.common.persistence.HibernateDao;
import com.company.manage.system.entity.UserRole;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by HuangYong on 2016/1/22.
 * desc:用户角色DAO
 */
@Repository
public class UserRoleDao extends HibernateDao<UserRole,Integer > {
    private static final String TAG = "UserRoleDao";

    /**
     * 删除用户角色
     * @param userId 用户id
     * @param roleId 角色id
     */
    public void deleteUserRole(Integer userId,Integer roleId){
        String hql = "delete UserRole ur where ur.user.id = ?0 and ur.role.id = ?1 ";
        batchExecute(hql,userId,roleId);
    }

    /**
     * 查询用户拥有的角色id集合
     * @param userId
     * @return
     */
    public List<Integer> findRoleId(Integer userId){

        String  hql = "select ur.role.id from UserRole ur where ur.user.id = ?0 ";
        Query query = createQuery(hql,userId);
        return query.list();
    }
} 